package com.coocaa.ops.admin.base.properties;

import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

/**
 * @author tangminghong
 * @date 2020-06-12
 */
@Data
@Component
@NacosConfigurationProperties(dataId = "admin-sys.yml", groupId = "${nacos.config.group}", autoRefreshed = true)
public class SystemProperties implements InitializingBean {

    /**
     * 域账号首次登陆是否在本系统添加默认账户
     */
    private Boolean enableDefaultAccount;
    /**
     * 默认账户角色
     */
    private String defaultRoles;

    /**
     * 审核者对应角色id
     */
    private String auditorIds;

    /**
     * 前端页面url
     */
    private String adminFrontUrl;

    /**
     * 是否初始化定时任务-启动程序时
     */
    private Boolean enableInitTimedJob;

    public static final class Constants{
        public static Boolean ENABLE_DEFAULT_ACCOUNT;
        public static String DEFAULT_ROLES;
        public static Integer[] AUDITOR_IDS = new Integer[]{};


    }

    @Override
    public void afterPropertiesSet() throws Exception {
        Constants.ENABLE_DEFAULT_ACCOUNT = enableDefaultAccount;
        Constants.DEFAULT_ROLES = defaultRoles;
        handleAuditorIds();

    }

    private void handleAuditorIds() {
        if (StringUtils.isNotBlank(auditorIds)) {
            String[] auditorIdArr = auditorIds.split(",");
            Constants.AUDITOR_IDS = new Integer[auditorIdArr.length];
            int i=0;
            for (String auditorId : auditorIdArr) {
                Constants.AUDITOR_IDS[i] = Integer.valueOf(auditorId);
                i++;
            }
        }
    }

    public void configListener() {

    }
}
